package com.example.jh352160.surfingtv.Index.customView.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.example.jh352160.surfingtv.Index.childpage.ThematicList;
import com.example.jh352160.surfingtv.R;

import java.util.List;

/**
 * Created by jh352160 on 2016/7/20
 */

public class ThematicRecyclerViewAdapter extends RecyclerView.Adapter<ThematicRecyclerViewAdapter.ViewHolder> {

    //private List<ImageView> imageViews;
    //private int[] images;
    private static Context context;
    private List<ImageView> imageViews;
    private List<String> urls;
    private List<Integer> contentId;

    public ThematicRecyclerViewAdapter(Context context, List<ImageView> imageViews, List<String> urls, List<Integer> contentId) {
        super();
        //this.imageViews=imageViews;
        //images= new int[]{R.drawable.thematic_image1, R.drawable.thematic_image2, R.drawable.thematic_image3, R.drawable.thematic_image4};
        this.imageViews = imageViews;
        //todo Why need this change
        //this.context = context;
        ThematicRecyclerViewAdapter.context = context;
        this.urls = urls;
        this.contentId = contentId;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(parent.getContext(), R.layout.item_index_thematic, null);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        Glide.with(context).load(urls.get(position)).into(holder.image);
        final int i = position;
        //holder.image=images.get(position);
        holder.image.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(context, ThematicList.class);
                intent.putExtra("contentId", contentId.get(i));
                context.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return imageViews.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        ImageView image;

        ViewHolder(View itemView) {
            super(itemView);
            image = (ImageView) itemView.findViewById(R.id.image);

//            image.setOnClickListener(new View.OnClickListener() {
//                @Override
//                public void onClick(View view) {
//                    Intent intent=new Intent(context, ThematicList.class);
//                    intent.putExtra("contentId",contentId.get(i));
//                    context.startActivity(intent);
//                }
//            });
        }
    }
}
